[−][src]Crate ci_info
ci_info
Provides current CI environment information.
This library main goal is to provide development/build tools such as cargo-make the needed information on the current CI environment.
The code is based on the ci-info npm module.
Examples
Get CI environment information
fn main() { // Just check if a CI environment is detected. let ci = ci_info::is_ci(); println!("Is CI: {}", ci); // Get CI environment information let info = ci_info::get(); println!("Is CI: {}", info.ci); if let Some(vendor) = info.vendor { println!("Vendor: {:#?}", vendor); println!("Name: {:#?}", info.name.unwrap()); } if let Some(pr) = info.pr { println!("Is PR: {:#?}", pr); } if let Some(branch_name) = info.branch_name { println!("Branch Name: {:#?}", branch_name); } }
Check if a CI environment is detected
fn main() { let ci = ci_info::is_ci(); println!("Is CI: {}", ci); }
Mocking CI environment
use ci_info::types::{CiInfo, Vendor}; fn main() { // create the CI info manually let mut mock_info = CiInfo::new(); mock_info.vendor = Some(Vendor::TravisCI); mock_info.ci = true; mock_info.pr = Some(true); mock_info.branch_name = Some("dev_branch".to_string()); // mock environment ci_info::mock_ci(&mock_info); let info = ci_info::get(); assert!(info.ci); assert!(info.pr.unwrap()); assert_eq!(info.vendor.unwrap(), Vendor::TravisCI); assert_eq!(info.name.unwrap(), "Travis CI"); assert_eq!(info.branch_name.unwrap(), "dev_branch"); // clear CI environment mock_info = CiInfo::new(); ci_info::mock_ci(&mock_info); let info = ci_info::get(); assert!(!info.ci); }
Installation
In order to use this library, just add it as a dependency:
[dependencies]
ci_info = "*"
There is optional serde
support that can be enabled via the serde-1
feature:
[dependencies]
ci_info = { version = "*", features = ["serde-1"] }
Contributing
License
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.
Modules
types | types |
Functions
get | Loads and returns the CI info of the current environment. |
is_ci | Returns true if a CI environment is detected. |
mock_ci | This function will modify the current environment variables to mock the requested CI vendor. |